import Types from '../actionTypes';

let initState = {
  count: 0,
  mynav: [],
  total: 0,
  dataSource: {
    color: ['#3398DB'],
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: ['2020-02-24', '2020-02-24', '2020-02-24', '2020-02-24'],
        axisTick: {
          alignWithLabel: true
        }
      }
    ],
    yAxis: [
      {
        type: 'value'
      }
    ],
    series: [
      {
        name: '直接访问',
        type: 'bar',
        barWidth: '60%',
        data: [1778, 154, 4578, 457]
      }
    ]
  }
};

export default (state = initState, action) => {
  const newState = JSON.parse(JSON.stringify(state));
  switch (action.type) {
    case Types.LEFT_NAV:
      newState.mynav = action.value;
      return newState;
    case Types.GET_INSTRUCTION_COUNT:
      newState.count = action.count;
      return newState;
    case Types.DATA_SOURCE:
      const {xAxisData, seriesData, total} = action.dataSource;
      newState.dataSource.xAxis[0].data = xAxisData;
      newState.dataSource.series[0].data = seriesData;
      newState.total = total;
      console.log('renducer', newState.dataSource);
      return newState;
    default:
      console.log('Types no match in leftNav.js ....');
  }
  return state;
}
